home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Program: CShell
- ** File: doevent.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1991 Apple Computer, Inc.
- ** All rights reserved.
- */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "CShell.h" /* Get the CShell includes/typedefs, etc. */
- #include "CShellCommon.h" /* Get the stuff in common with rez. */
- #include "CShell.protos" /* Get the prototypes for CShell. */
-
- #ifndef __DESK__
- #include <Desk.h>
- #endif
-
- #ifndef __DISKINIT__
- #include <DiskInit.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __TEXTEDITCONTROL__
- #include "TextEditControl.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern Cursor *gCurrentCursor;
-
- static void ResizeContent(WindowPtr window);
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* Do the right thing for an event. Determine what kind of event it is, and
- ** call the appropriate routines.
- */
-
- #pragma segment Main
- void DoEvent(EventRecord *event)
- {
- short part, err;
- WindowPtr window;
- char key;
- Point pt;
- Rect contentRct, oldRct, growLimits;
- long size;
- FileRecHndl frHndl;
-
- switch(event->what) {
-
- case mouseDown:
- gCurrentCursor = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- part = FindWindow(event->where, &window);
- if (part != inContent) DoSetCursor(&QD(arrow));
-
- switch(part) {
-
- case inContent:
- if (window != FrontWindow()) {
- SelectWindow(window);
- if (IsAppWindow(window)) {
- DoUpdate(window);
- contentRct = GetWindowContentRect(window);
- if (PtInRect(event->where, &contentRct))
- DoEvent(event);
- }
- /* Do first click if over board. */
- } else
- DoContentClick(window, event);
- break;
-
- case inDrag:
- DragWindow(window, event->where, &QD(screenBits.bounds));
- break; /* Pass screenBits.bounds to
- ** get all gDevices. */
-
- case inGoAway:
- if (TrackGoAway(window, event->where)) {
- DisposeOneWindow(window, iClose);
- }
- break;
-
- case inGrow:
- oldRct = GetWindowContentRect(window);
- SetRect(&growLimits, kMinWindowWidth, kMinWindowHeight,
- kMaxWindowWidth, kMaxWindowHeight);
- if (size = GrowWindow(window, event->where, &growLimits)) {
- pt = *(Point *)&size;
- SizeWindow(window, pt.h, pt.v, true);
- ResizeContent(window);
- }
- break;
-
- case inMenuBar: /* Process mouse menu command (if any). */
- AdjustMenus();
- DoMenuCommand(MenuSelect(event->where));
- break;
-
- case inSysWindow: /* Let the system handle the mouseDown. */
- SystemClick(event, window);
- break;
-
- case inZoomIn:
- case inZoomOut:
- if (TrackBox(window, event->where, part)) {
- ZoomToWindowDevice(window, 640, 400, part, true);
- ResizeContent(window);
- }
- break;
-
- }
- break;
-
- case activateEvt:
- gCurrentCursor = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- DoActivate((WindowPtr)event->message,
- (event->modifiers & activeFlag));
- break;
-
- case autoKey:
- case keyDown: /* Check for menukey equivalents. */
- key = event->message & charCodeMask;
- if (event->modifiers & cmdKey) { /* Command key down. */
- if (event->what == keyDown) {
- AdjustMenus();
- /* Enable/disable/check menu items properly. */
- DoMenuCommand(MenuKey(key));
- }
- break;
- }
-
- if (!IsAppWindow(window = FrontWindow())) break;
- frHndl = (FileRecHndl)GetWRefCon(window);
-
- if (key == 0x03) {
- SendMessage(frHndl, kTextMssg);
- break;
- }
- if (CTEKey(event)) {
- (*frHndl)->fileState.docDirty = true;
- AdjustMenus(); /* Avoid unnecessary DoCursor() and speed */
- return; /* up TextEdit entry. */
- }
- break;
-
- case diskEvt:
- gCurrentCursor = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- if (HiWord(event->message) != noErr) {
- SetPt(&pt, kDILeft, kDITop);
- err = DIBadMount(pt, event->message);
- }
- break; /* It is not a bad idea to at least call DIBadMount
- ** in response to a diskEvt, so that the user can
- ** format a floppy.
- */
- case kHighLevelEvent:
- gCurrentCursor = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- DoHighLevelEvent(event);
- break;
-
- case kOSEvent:
- gCurrentCursor = nil;
- /* No shortcuts when we recalculate the cursor region. */
-
- switch ((event->message >> 24) & 0x0FF) {
- /* Must logical and with 0x0FF to get only low byte. */
- /* High byte of message. */
-
- case kMouseMovedMessage:
- break;
-
- case kSuspendResumeMessage:
- /* Suspend/resume is also an activate/deactivate. */
- gInBackground = !(event->message & kResumeMask);
- DoActivate(FrontWindow(), !gInBackground);
- break;
- }
- break;
-
- case updateEvt:
- DoUpdate((WindowPtr)event->message);
- break;
-
- }
-
- DoCursor(false, 0);
- AdjustMenus();
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when a window is activated or deactivated. */
-
- #pragma segment Main
- void DoActivate(WindowPtr window, Boolean becomingActive)
- {
- NotifyCancel();
-
- if (IsAppWindow(window)) {
- SetPort(window);
- CTEWindActivate(window, becomingActive);
- DoDrawGrowIcon(window, false, false); /* Just draw the icon. */
- DoDrawControls(window, true); /* Redraw just the scrollbars. */
- SetOrigin(0, 0);
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when an update event is received for a window. It calls
- ** ImageDocument to draw the contents of an application window. As an
- ** effeciency measure that does not have to be followed, it calls the drawing
- ** routine only if the visRgn is non-empty. This will handle situations where
- ** calculations for drawing or drawing itself is very time-consuming.
- */
-
- #pragma segment Main
- void DoUpdate(WindowPtr window)
- {
- if (IsAppWindow(window)) {
- BeginUpdate(window); /* This sets up the visRgn. */
- if (!EmptyRgn(window->visRgn)) { /* Draw if updating needs doing. */
- SetPort(window);
- ImageDocument((FileRecHndl)GetWRefCon(window));
- }
- EndUpdate(window);
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* This is called when a mouse-down event occurs in the content of a window.
- ** Other applications might want to call FindControl, TEClick, etc., to
- ** further process the click.
- */
-
- #pragma segment Main
- void DoContentClick(WindowPtr window, EventRecord *event)
- {
- Point clickLoc;
- FileRecHndl frHndl;
-
- if (!IsAppWindow(window)) return;
-
- SetPort(window);
-
- clickLoc = event->where;
- GlobalToLocal(&clickLoc);
-
- if (CTEClick(event)) return;
- /* If TextEdit control handled the click, we are done. */
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- if ((*frHndl)->fileState.readOnly) return;
- /* Don't allow changes if read-only. */
- }
-
-
-
- /*****************************************************************************/
-
-
-
- #pragma segment Main
- void ResizeContent(WindowPtr window)
- {
- FileRecHndl frHndl;
- WindowPtr oldPort;
- short i;
- Rect rct;
- TEHandle teHndl;
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- oldPort = SetFilePort(frHndl);
-
- for (i = 0; i < 2; ++i) {
- rct = window->portRect;
- --rct.top;
- --rct.left;
- rct.right -= 14;
- rct.bottom = rct.top + (rct.bottom - rct.top + 1) / 2;
- if (i) {
- rct.top = rct.bottom - 1;
- rct.bottom = window->portRect.bottom + 1;
- }
-
- teHndl = (*frHndl)->doc.inBox;
- if (i) teHndl = (*frHndl)->doc.outBox;
-
- CTESize(teHndl, rct.right - rct.left, rct.bottom - rct.top);
- CTEMove(teHndl, rct.left, rct.top);
- }
-
- SetPort(oldPort);
- }
-
-
-
-